package com.tduck.cloud.datav.service.charts;


import cn.hutool.core.map.MapUtil;
import com.google.common.collect.Lists;
import com.tduck.cloud.datav.request.ChartDataRequest;
import com.tduck.cloud.datav.service.BaseChartDataService;
import com.tduck.cloud.datav.vo.WordCloudVO;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Component
public class WordCloudChartDataService extends BaseChartDataService {


    @Override
    public Map<String, Object> getChartData(ChartDataRequest request) {
        for (ChartDataRequest.IndexField field : request.getIndex()) {
            List<Object> fieldDistinctList = dataSearchTemplate.getFieldDistinctList(request.getIndexName(), field.getId());
            List<WordCloudVO> list = fieldDistinctList.stream().map(item -> new WordCloudVO(item.toString(), 1, 1)).collect(Collectors.toList());
            return MapUtil.of("data", list);
        }
        return MapUtil.of("data", Lists.newArrayList());
    }
}
